﻿using System.Windows;

namespace MessageBoxWPF
{
    public class MessageBoxNotifier : IMessageBoxNotifier
    {
        private static MessageBoxNotifier _window = new MessageBoxNotifier();
        public static MessageBoxNotifier MessageBox { get { return _window;    } }

        public Result Show(string message)
        {
            var mb = new MessageBoxVM { Title = string.Empty, Message = message, Buttons = ButtonType.OkCancel };

            var mbx = new MessageBox { DataContext = mb }.ShowDialog();
            return mb.Result;
        }

        public Result Show(string title, string message)
        {
            var mb = new MessageBoxVM { Title = title, Message = message, Buttons = ButtonType.OkCancel };

            var mbx = new MessageBox { DataContext = mb }.ShowDialog();
            return mb.Result;
        }

        public Result Show(string message, string title, MessageBoxButton button, MessageBoxImage image)
        {

            ButtonType bt = ButtonType.Ok;
            MessageBoxType mt = MessageBoxType.Information;

            switch (button)
            {
                case MessageBoxButton.OK:
                    bt = ButtonType.Ok; break;
                case MessageBoxButton.OKCancel:
                    bt = ButtonType.OkCancel; break;
                case MessageBoxButton.YesNo:
                    bt = ButtonType.YesNo; break;
                case MessageBoxButton.YesNoCancel:
                    bt = ButtonType.YesNoCancel; break;
            }

            switch (image)
            {
                case MessageBoxImage.Error:
                    mt = MessageBoxType.Exclamation;
                    break;
                case MessageBoxImage.Exclamation:
                    mt = MessageBoxType.Exclamation;
                    break;
                case MessageBoxImage.Information:
                    mt = MessageBoxType.Information;
                    break;
                case MessageBoxImage.None:
                    break;
                case MessageBoxImage.Question:
                    mt = MessageBoxType.Question;
                    break;

            }

            var mb = new MessageBoxVM { Title = title, Message = message, Type = mt, Buttons = bt };

            var mbx = new MessageBox { DataContext = mb }.ShowDialog();
            return mb.Result;
        }

        public Result Show(string title, string message,  MessageBoxType type, ButtonType buttons)
        {
            var mb = new MessageBoxVM { Title = title, Message = message, Type = type, Buttons = buttons };

            var mbx = new MessageBox { DataContext = mb }.ShowDialog();
            return mb.Result;
        }

        public Result Show(string title, string message, MessageBoxType type, ButtonType buttons, Result defultResult)
        {
            var mb = new MessageBoxVM { Title = title, Message = message, Type = type, Buttons = buttons, Result = defultResult };

            var mbx = new MessageBox { DataContext = mb }.ShowDialog();
            return mb.Result;
        }
    }
}
